﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using RESTScrum.Dominio;
using RESTScrum.Persistencia;
using System.ServiceModel.Web;
using System.Net;

namespace RESTScrum
{
    public class Materiales : IMateriales
    {
        private MaterialDAO dao = new MaterialDAO();

        public Material CrearMaterial(Material materialACrear)
        {
            //Validacion si existe el material creado
            Material existe = ObtenerMaterial(materialACrear.Codigo);

            if (existe != null )
                throw new WebFaultException<Error>(
                    new Error() {
                    CodigoNegocio = "C01",
                    MensajeNegocio = "Material ya existe"},
                    HttpStatusCode.InternalServerError);
  
            //if ("6".Equals(materialACrear.Codigo))
            //    throw new WebFaultException<string>("Material Errado",
            //        System.Net.HttpStatusCode.NotFound);

            return dao.Crear(materialACrear);
        }

        public Material ObtenerMaterial(string codigo)
        {
            return dao.Obtener(codigo);
        }

        public Material ModificarMaterial(Material materialAModificar)
        {
            return dao.Modificar(materialAModificar);
        }

        public void EliminarMaterial(string codigo)
        {
            dao.Eliminar(codigo);
        }

        public List<Material> ListarMateriales()
        {
            return dao.ListarTodos();
        }

    }
}
